from django.shortcuts import render

# Create your views here.
from rest_framework import generics
from .models import LocDevices
from .serializers import LocDevicesSerializer
from .filters import LocDevicesFilter
from rest_framework.response import Response


class LocDevicesView(generics.GenericAPIView):
    queryset = LocDevices.objects.all()
    serializer_class = LocDevicesSerializer
    filter_class = LocDevicesFilter
    def get(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)
        serializer = self.get_serializer(queryset, many=True)
        res_data = {}
        res_data['data'] = serializer.data
        res_data['code'] = '200'
        res_data['count'] = len(queryset)
        return Response(res_data)
